package erp.server.resource.controller;

import erp.server.base.response.JsonResult;
import erp.server.resource.pojo.dto.ResourceDTO;
import erp.server.resource.pojo.vo.ResourceDetailVO;
import erp.server.resource.pojo.vo.ResourceIndexVO;
import erp.server.resource.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/resources")
public class ResourceController {


    @Autowired
    ResourceService resourceService;

    @PostMapping("add-new")
    public JsonResult addNew(ResourceDTO resourceDTO) {
        System.out.println("resourceDTO = " + resourceDTO);
        resourceService.addNew(resourceDTO);
        return JsonResult.ok();
    }

    @GetMapping("list")
    public JsonResult listForIndex() {
        List<ResourceIndexVO> list = resourceService.listForIndex();
        return JsonResult.ok(list);
    }

    @GetMapping("{id}/detail")
    public JsonResult detailById(@PathVariable Long id) {
        ResourceDetailVO resourceDetailVO = resourceService.detailById(id);
        return JsonResult.ok(resourceDetailVO);
    }

    @GetMapping("{orgId}")
    public JsonResult listForIndexByOrgId(@PathVariable Long orgId) {
        System.out.println("userId = " + orgId);
        List<ResourceIndexVO> list = resourceService.listForIndexByOrgId(orgId);
        return JsonResult.ok(list);
    }

    @PostMapping("{id}/delete")
    public JsonResult deleteById(@PathVariable Long id) {
        resourceService.deleteById(id);
        return JsonResult.ok();
    }


}
